package com.itheima.reggie.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class MyRedisAutoConfig {


    @Bean
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<Object, Object> RedisTemplate = new RedisTemplate<>();
        //Redis有数据库的，所有猜要连接
        RedisTemplate.setConnectionFactory(redisConnectionFactory);
        //键的设置
        RedisTemplate.setKeySerializer(new StringRedisSerializer());
        //序列化没问题，但是反序列化有的会出问题
//        RedisTemplate.setValueSerializer( new GenericJackson2JsonRedisSerializer());
        return RedisTemplate ;
    }
}
